<!--
/**************************************************
* @ balancepayrecv.jsp
*
* Copyright   2006 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/04/17, Jenny Li
*  1) first release
*  2) 修改当有多笔下级单位时，计算金额的错误
/**************************************************
-->
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="../../common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>录入应收</title>
		<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<LINK href="<%=root%>/css/caigouxitong.css"" type=text/css rel=stylesheet>		
	<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
	<SCRIPT language="JavaScript" src="<%=root%>/js/calendar.js"></SCRIPT>
	<SCRIPT language="JavaScript" src="<%=root%>/js/hi-check.js"></SCRIPT>	
	<%
		HashMap tMap = (HashMap)request.getAttribute("map");
		String deptName = (String)tMap.get("orgname");
		String deptId = (String)tMap.get("org");
		String balYm = (String)tMap.get("balanceym");
		String balSum = (String)tMap.get("balancsum");
		String deptType = (String)tMap.get("deptcategory");
		String recDay = (String)tMap.get("recvday");
	%>
	<script>
		var counter;
		function process(val){
			if(val == 'Q'){
				orderqueryform.action = "accounts1.html";
    			orderqueryform.submit();			
			}else if(val == 'T'){
			}

		}
		
		function changeAccount(obj , account)
		{
			if (obj.checked)
			{
				//格式化小数位数
				var sum1 = parseFloat(document.all["sum1"].value) + parseFloat(account);
				var temp1 = sum1.toFixed(4);
				document.all["sum1"].value = temp1;
			}
			else
			{
				//格式化小数位数			
				var sum2 = parseFloat(document.all["sum1"].value) - parseFloat(account);
				var temp2 = sum2.toFixed(4);
				document.all["sum1"].value = temp2;
			}
		}
		function changeAllAccount(obj,count){
			var totalAmt=0;
			SelectAllCheckBox(balancerecvform,'subOrgBalMsg');
			if(count>1){
				for(i=0; i<count; i++){
					var temp = document.getElementById('amt' + i);		
					
					totalAmt = totalAmt + parseFloat(temp.innerText);
				}
			}else{
				var temp = document.getElementById('amt0');
				totalAmt = totalAmt + parseFloat(temp.innerText);
			}			
			//格式化为了显示四位小数//
			var temp1 = parseFloat(<%=balSum%>) + totalAmt;
			temp1 = temp1.toFixed(4);
			var temp2 = parseFloat(<%=balSum%>);	
			temp2 = temp2.toFixed(4);
			//格式化为了显示四位小数//
			if (obj.checked){
				document.all["sum1"].value = temp1;
			}else{
				document.all["sum1"].value = temp2;
			}
		}
		function recvSubmit(){
			var type1 = 0;
			var type2 = 1;
			var type3 = 0;
			var type4 = 0;
			var type5 = 0;
			var type6 = 0;		
			var checkChar = "0123456789.";
			if(isEmpty(document.all["sum1"].value)){
				alert("第1行金额栏位必填！");
				return false;
			}else{
				if(HiScript.checkDecimal(document.all["sum1"].value,checkChar,4,"第1行金额栏")){
					return false;
				}	    		
			}
			if(isEmpty(document.all("recCostDate1").value)){
				alert("第1行收款日期栏位必填！");
				return false;
			}
			if(isEmpty(document.all["principal1"].value)){
				alert("第1行负责人栏位必填！");
				return false;			
			}
			var temp = document.getElementsByName("sum");
			var date = document.getElementsByName("recCostDate");
			var princ = document.getElementsByName("principal");
			var costType = document.getElementsByName("Select1");		
			var feeType = document.getElementsByName("Select2");	
			for(i=2; i<=temp.length; i++){
				if(!isEmpty(temp[i-1].value)){
					var iFields1 = new Array();
	        		iFields1[0] = 'sum'+ i +'||金额||Y||1-20||#.';
//					if(HiScript.value('balancerecvform',iFields1)==false) {
//						return false;
//					} 				

					var name = "sum"+(i);
					var sum = document.all[name].value;
					if(HiScript.checkDecimal(sum,checkChar,4,"第"+i+"行金额栏")){
						return false;
					}	
					if(isEmpty(date[i-1].value)){
						alert("第" + i +"行收款日期必填！");
						return false;
					}
					if(isEmpty(princ[i-1].value)){
						alert("第" + i +"行负责人必填！");
						return false;						
					}
					//alert(costType[m-1].value);
					if(costType[i-1].value == '0'){
						type1 = type1 + 1;
					}else if(costType[i-1].value == '1'){
						type2 = type2 + 1;
					}else if(costType[i-1].value == '2'){
						type3 = type3 + 1;
					}else if(costType[i-1].value == '3'){
						type4 = type4 + 1;
					}else if(costType[i-1].value == '4'){
						type5 = type5 + 1;
					}else if(costType[i-1].value == '5'){
						type6 = type6 + 1;
					}
				}
			}															
//			if(parseInt(type1) > 1 || parseInt(type2) > 1 || parseInt(type3) > 1 
//				|| parseInt(type4) > 1 || parseInt(type5) > 1 || parseInt(type6) > 1){
//				alert("不能存在费用类型相同的两条数据!");
//				return false;
//			}
			var ary = new Array();
			ary[0] = "<%=deptId%>";
			ary[1] = "<%=balYm%>";	
			var common; 			
			//费用类型

			common = new Array();
			
			var tCostType = "";
			for(i=0; i<costType.length;i++){
				common[i] = costType[i].value;
			}

			ary[2] = common;
			//收付类型
			common = new Array();			
			
			for(i=0; i<feeType.length;i++){
				common[i] = feeType[i].value;
			}			
			ary[3] = common;
			//金额
			common = new Array();
			for(i=0; i<temp.length;i++){
				common[i] = temp[i].value;
			}
			ary[4] = common;
			//签收日期
			common = new Array();
			for(i=0; i<date.length;i++){
				common[i] = date[i].value;
			}			
			ary[5] = common;
			//签收人
			common = new Array();
			for(i=0; i<princ.length;i++){
				common[i] = princ[i].value;
			}						
			ary[6] = common;
			
			ary[7] = balancerecvform.notes.value;
			
			var suborgid = "";
			if(balancerecvform.subOrgBalMsg!=null){
				if(balancerecvform.subOrgBalMsg.length > 1){
					for(i=0; i<balancerecvform.subOrgBalMsg.length;i++){
						if(balancerecvform.subOrgBalMsg[i].checked){
							suborgid = suborgid + balancerecvform.subOrgBalMsg[i].value;
						}
					}
					
				}else{
						if(balancerecvform.subOrgBalMsg.checked){
							suborgid = suborgid + balancerecvform.subOrgBalMsg.value;
						}					
				}
			}
			ary[8] = suborgid;
			if(!confirm("是否确定生成收付款?")){
				return false;				
			}
			window.returnValue=ary;
			window.close();
			
		}
	
			</script>
	</head>
	<body BGCOLOR="#f2f2f2" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
		<form name="balancerecvform" method="post">
			<p><FONT face="宋体"></FONT><br>
			</p>
			<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
				<tr>
					<td height="20">
						<table width="100%" border="0" cellspacing="0" cellpadding="1">
							<tr height="20">
								<td height="30" width="758" class="mtxt_black">
								<%
									if(deptType.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
								%>
								录入应收
								<%			
									}else {
								%>
								录入应付
								<%
									}
								%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td class="bg_line" height="2"></td>
				</tr>
			</table>
			<br>
			<table class="bg_table" id="Table1" cellspacing="1" cellpadding="0" style="PADDING-RIGHT:5px; PADDING-LEFT:5px"
				width="98%" align="center" border="0">
				<TR height="20">
					<TD class="bg_column" align="left" colspan="2">
						<b>单位名称：<%=deptName%></b>
					</TD>
					<TD class="bg_column" align="right" colspan="2">
						<b>月份：<%=balYm.substring(0,4) + "年" + balYm.substring(4,6) + "月" %></b>
					</TD>
				</TR>
			</table>
			<table class="bg_table" id="tableId" cellSpacing="1" cellPadding="2" width="98%" align="center"
				border="0">
				<tr class="bg_column" height="20">
					<td class="top" align="center" colSpan="4"><b>合同信息</b>
					</td>
				</tr>
				<tr class="bg_column" height="20">
					<td class="top" align="center">
						<div class="txt_content" align="center"></div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">类型</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">合同内容</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">费用信息</div>
					</td>
				</tr>
				<%
					ArrayList tList = (ArrayList)tMap.get("bargain");
					if(tList != null && tList.size() > 0){
						for(int i=0; i < tList.size(); i++){
							String[] tStr =(String[]) tList.get(i);
							
				%>
				<tr class="bg_row_odd" height="20">
					<td class="top" align="center">
						<div class="txt_content" align="center">
						<%
							if(tStr[2].equals(GSBaseConstants.MAIN_BARGAIN)){
						%>
							<a href="<%=response.encodeURL(root + "/A180207.do")%>?bgnId=<%=tStr[0]%>&bgnSerl=<%=tStr[1]%>" target="_blank">查看合同</a>
						<%
							}
						%>
						</div>
					</td>
					<td class="top" align="center">
					<div class="txt_content" align="center">
						<%
						if(tStr[2].equals(GSBaseConstants.MAIN_BARGAIN)){
						%>
						主合同
						<%
						}else{
						%>
						副合同
						<%	
						}
						%>
					</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center"><%=tStr[3]%></div>
					</td>
					<td class="top" align="center">
						<%
							String[] temp = tStr[4].split(";");
							for(int j=0; j<temp.length;j++){
						%>
						<div class="txt_content" align="center"><%=temp[j]%></div>
						<%} %>
					</td>
				</tr>				
				<%
						}
					}
				
				%>

			</table>
			<br>
			<%
				if(deptType.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
					tList = (ArrayList)tMap.get("suborg");
					if(tList != null && tList.size() > 0){
			%>
			<table class="bg_table" id="Table3" cellSpacing="1" cellPadding="2" width="98%" align="center"
				border="0">
				<tr class="bg_column" height="20">
					<td class="top" align="left" colSpan="7"><b>下属公司结算信息列表（勾选款项，与本公司款项合并结算）</b>
					</td>
				</tr>
				<tr class="bg_column" height="20">
					<td class="top" align="center">
						<INPUT type="checkbox" ID="Checkbox1" NAME="indexs" onClick="changeAllAccount(this,<%=tList.size()%>)">
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">订货单位</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">结算年份</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">结算月份</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">金额（元）</div>
					</td>

				</tr>
				<%
					for(int i=0; i<tList.size(); i++){
						GSBalanceMsgBean tBean = (GSBalanceMsgBean)tList.get(i);
				%>
				<tr class="bg_row_odd" height="20">
					<td class="top" align="center">
						<INPUT type="checkbox"  NAME="subOrgBalMsg" onclick="changeAccount(this,'<%=tBean.getGs_balance_sum()%>');" value="<%=tBean.getGs_workcorp_id()%>">
					</td>
					<td class="top" align="center">
						<%= GSBaseManager.getOrgNameByOrgId(tBean.getGs_workcorp_id())%>
					</td>
					<td class="top" align="center">
						<%=balYm.substring(0,4)%>年
					</td>
					<td class="top" align="center"><%=balYm.substring(4,6)%>月
					</td>
					<td class="top" align="center" id="amt<%=i%>"><%=StringUtils.formatEDouble(tBean.getGs_balance_sum(),4)%>
					</td>
					<!--<td class="top" align="center">2006-05-20
					</td>
					<td class="top" align="center">×××
					</td>-->
				</tr>				
				<%
					}
				%>


			</table>			
			<%					
					}
				}
			%>

			<br>
			<table class="bg_table" id="Table2" cellSpacing="1" cellPadding="2" width="98%" align="center"
				border="0">
				<tr class="bg_column" height="20">
					<td class="top" align="center">
						<div class="txt_content" align="center">费用类型</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">类型</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">金额（元）</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">收款日期</div>
					</td>
					<td class="top" align="center">
						<div class="txt_content" align="center">负责人</div>
					</td>
				</tr>
				<%
					for(int i=1; i<=6; i++){
				%>
				<tr class="bg_row_odd" height="20">
					<td class="top" align="center">
							<%
								if(i == 1){
							%>
								<SELECT ID="Select1" NAME="Select1" disabled>
							<% 
								}else{
							%>
							<SELECT ID="Select1" NAME="Select1">
							<%
								}
								ArrayList tFeeTypes = (ArrayList)tMap.get("feetype");
								for(int j=0; j<tFeeTypes.size(); j++){
									GSBalanceFeeBean tBalFeeBean = (GSBalanceFeeBean)tFeeTypes.get(j);
									if(i==1 && tBalFeeBean.getGs_fee_type().equals("零配件结算款（维修类）")){
							%>
										<option value="<%=tBalFeeBean.getGs_fee_type_no()%>" selected><%=tBalFeeBean.getGs_fee_type()%></option>
							<%			
									}else{
							%>	
										<option value="<%=tBalFeeBean.getGs_fee_type_no()%>"><%=tBalFeeBean.getGs_fee_type()%></option>
							<%		
									}
		
								}
							%>
						</SELECT>
					</td>
					<td class="top" align="center">
						<SELECT ID="Select2" NAME="Select2">
							<%
								String[][] tStr = GSBaseManager.getAllPayType();
								for(int j=0; j<tStr.length; j++){
									String[] temp = tStr[j];
									if(deptType.equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
										if(temp[0].equals(GSBaseConstants.RECEIVE_TYPE)){
							%>
							<option  value="<%=temp[0]%>" selected><%=temp[1]%></option>
							<%			
										}else{
							%>
							<option value="<%=temp[0]%>"><%=temp[1]%></option>
							<%
										}
									}else if(deptType.equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)){
										if(temp[0].equals(GSBaseConstants.PAYMENT_TYPE)){
							%>
							<option  value="<%=temp[0]%>" selected><%=temp[1]%></option>
							<%
										}else{
							%>				
							<option value="<%=temp[0]%>"><%=temp[1]%></option>
							<%
										}
									}
								}
							%>
						</SELECT>
					</td>
					<td class="top" align="center">
						<INPUT type="text" ID="sum<%=i%>" NAME="sum" size="20" value="<%=(i==1)?balSum:""%>" maxlength="20">
					</td>
					<td class="top" align="center">
						<INPUT type="text" ID="recCostDate<%=i%>" NAME="recCostDate" size="10" readonly onfocus='setday(this)' value="<%=(i==1)? recDay:""%>">
					</td>
					<td class="top" align="center">
						<INPUT type="text" ID="principal<%=i%>" NAME="principal" maxlength="20" size="10">
					</td>
				</tr>				
				<%
					}
				%>


			</table>
			<br>
			<table class="bg_table" id="Table4" cellSpacing="1" cellPadding="2" width="98%" align="center"
				border="0">
				<tr class="bg_column" height="20">
					<td class="top" align="center" width="15%">备注
					</td>
					<td class="bg_row_odd" align="left" width="85%">
						<TEXTAREA rows="5" cols="20" ID="Textarea1" NAME="notes" style="WIDTH:95%"></TEXTAREA>
					</td>
				</tr>
			</table>
		</form>
		<p align="center">
			<INPUT type="button" value="确定" ID="Button1" NAME="Button1" class="kuang" onclick="recvSubmit()">
			&nbsp;&nbsp;<INPUT type="button" value="关闭" NAME="Button2" class="kuang" onclick="self.close();">
		</p>
	</body>
</html>
